package org.example.command;

import com.alipay.remoting.exception.CodecException;
import com.alipay.remoting.serialization.SerializerManager;
import lombok.Builder;
import lombok.Data;
import org.example.order.CmdType;
import org.example.order.MatchEvent;
import org.example.order.OrderDirection;
import org.example.order.OrderType;

import java.io.Serializable;
import java.util.List;

@Data
public class OrderCmd implements Serializable {
    public long timestamp;
    public int mid;
    public long uid;
    public CmdType type;
    public int code;
    public OrderDirection direction;
    public long price;
    public long volumn;
    public long oid;
    public OrderType orderType;

    public List<MatchEvent> matchEventList;
    public CmdResultCode resultCode;

    public boolean isSell() {
        return OrderDirection.SELL.equals(this.direction);
    }

    public byte[] serialize() throws CodecException {
        return SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(this);
    }

    public static OrderCmd deserialize(byte[] source) throws CodecException {
        return SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize(source,OrderCmd.class.getName());
    }
}
